<?php
if (!isset($_SESSION)) {
  session_start();
}

//时间设置
//error_reporting(E_ALL);//错误报告级别
error_reporting(E_ERROR | E_PARSE);//错误报告级别
set_magic_quotes_runtime(0);
function_exists('date_default_timezone_set') && date_default_timezone_set('Etc/GMT-8');//设置程序时间是格林时间减8，是北京时间


//php低版本兼容传递变量
if(PHP_VERSION < '4.1.0') {
	$_GET = &$HTTP_GET_VARS;
	$_POST = &$HTTP_POST_VARS;
	$_COOKIE = &$HTTP_COOKIE_VARS;
	$_SERVER = &$HTTP_SERVER_VARS;
	$_ENV = &$HTTP_ENV_VARS;
	$_FILES = &$HTTP_POST_FILES;
}

if(!get_magic_quotes_gpc()){
	Add_S($_POST);
	Add_S($_GET);
	Add_S($_COOKIE);
	Add_S($_SESSION);
}
//靠这个设置太BT了 日
//Add_S($_FILES); 
//定义环境
define('ZZQSS',true);
define('ROOT_PATH', str_replace("\\", '/', dirname(__FILE__)));
$php_self = isset($_SERVER['PHP_SELF']) ? $_SERVER['PHP_SELF'] : $_SERVER['SCRIPT_NAME'];
define('HTTP_REFERER', isset($_SERVER['HTTP_REFERER']) ? $_SERVER['HTTP_REFERER'] : '');
define('PHP_SELF',  htmlentities($php_self));
define('ROOT_DIR',  substr(PHP_SELF, 0, strrpos(PHP_SELF, '/')));
define('SITE_URL', "http://".$_SERVER['HTTP_HOST'].ROOT_DIR);
define('INC_PATH', ROOT_PATH.'/includes');

//模板缓存目录
define('TPL_CACHEPATH', ROOT_PATH.'/data/cache_template');
//系统设置变量缓存目录
define('CFG_CACHEPATH', ROOT_PATH.'/data/syscache');
define('DATA_CACHEPATH', ROOT_PATH.'/data/datacache/');

//安装
if(!file_exists(ROOT_PATH.'/data/install.lock')) {
	header("Location: install/index.php");//安装
	exit();
}


//获取当前时间
$timestamp = time();
//声明几个全局变量users 存储用户信息
$_USERS=array();
$ERROR_MSG="";

$_CONFIGS[]=array();
$_CONFIGS['money_state']=array(0=>'未收款',1=>'部分收款',2=>'已收款');
$_CONFIGS['shipping_state']=array(0=>'未发货',1=>'已发货');
$_CONFIGS['order_state']=array(0=>'未取消',1=>'完成',2=>'已取消');

//配置文件包含
include_once( ROOT_PATH.'/config.inc.php');
//包含后台配置参数
require_once(CFG_CACHEPATH.'/config.cache.inc.php');
//定义模板目录
if(is_dir(ROOT_PATH."/templates/{$cfg_templet_name}"))
{	//设置后台配置模板目录
	define('TPL_PATH', ROOT_PATH."/templates/{$cfg_templet_name}");
	define('TPL', 'templates/'.$cfg_templet_name.'/');//定义模板使用的路径
}else{
	//设置参数不是目录则设置defalut为模板目录
	define('TPL_PATH', ROOT_PATH."/templates/default");
	define('TPL', 'templates/default/');//定义模板使用的路径
}
//共用函数包含
include_once( ROOT_PATH.'/includes/fun_common.php');
//模板函数包含
include_once(ROOT_PATH.'/includes/fun_template.php');
//数据库初始化
require_once ROOT_PATH.'/includes/db_mysql.class.php';

$db = new dbstuff;
$db->connect($dbhost, $dbuser, $dbpw, $dbname, $pconnect);
unset($dbhost, $dbuser, $dbpw, $dbname, $pconnect);

function Add_S(&$array){
	if(is_array($array)){
		foreach($array as $key=>$value){
			if(!is_array($value)){
				$array[$key]=addslashes($value);
			}else{
				Add_S($array[$key]);
			}
		}
	}
}
//地区相关变量
$_cityid=0;
$_citylist=array();
$_cityname="";
include_once(INC_PATH."/city.class.php");
$city=new CityClass();
$_cityid=$city->getcity();
if(!($_citylist=cache_read('citydata.php'))){
$_citylist=$city->getdata("","state=1");
$city->cachedata();//写入文件
}
$_cityname=$city->getcityname($_cityid);
checkauth();//检查用户登录
checkkey();
?>